<?php
class Mail_utils {
	
	private $ci;
	
	public function __construct()
	{
		$this->ci = & get_instance();
	}
	
	public function get_mail_url($mail)
	{
		return 'http://'.substr($mail, strpos($mail, '@') + 1);
	}
	
	public function send_mail($to_mail)
	{
		//get setting
		$this->ci->load->model('setting_model');
		$setting_mail = $this->ci->setting_model->get_value_by_name(Variable::SETTING_MAIL);
		$setting_password = $this->ci->setting_model->get_value_by_name(Variable::SETTING_PASSWORD);
	
		//mail content
		$title = '轻松记注册开通邮件';
		$content_header = '<html><body>';
		$content_body = '<h3>亲爱的'.$to_mail.':</h3>'
		.'<p>感谢您注册轻松记，请点击链接完成注册。</p>'
		.'<a href="'.site_url('user/validate/'.md5($to_mail)).'">点击验证轻松记帐户</a>'
		.'<p>如果上述文字点击无效，请把下面网页地址复制到浏览器地址栏中打开：</p>'
		.'<a href="'.site_url('user/validate/'.md5($to_mail)).'">'.site_url('user/validate/'.md5($to_mail)).'</a>'
		.'<p>如果您没有注册轻松记，请忽略此邮件。</p>';
		$content_footer = '</body></html>';
		$content = $content_header.$content_body.$content_footer;
	
		//send mail
		$sae_mail = new SaeMail();
		$sae_mail->setOpt(array('content_type'=>'HTML'));
		$ret = $sae_mail->quickSend($to_mail, $title, $content , $setting_mail, $setting_password);
		$sae_mail->clean();
	}
	
	public function send_forgot_mail($to_mail, $change_key)
	{
		//get setting
		$this->ci->load->model('setting_model');
		$setting_mail = $this->ci->setting_model->get_value_by_name(Variable::SETTING_MAIL);
		$setting_password = $this->ci->setting_model->get_value_by_name(Variable::SETTING_PASSWORD);
		
		//mail content
		$title = '轻松记重置密码邮件';
		$content_header = '<html><body>';
		$content_body = '<h3>亲爱的'.$to_mail.':</h3>'
		.'<p>您正通过邮件重置密码，请点击链接完成重置。</p>'
		.'<a href="'.site_url('user/reset').'/'.$change_key.'">打开重置页面</a>'
		.'<p>如果上述文字点击无效，请把下面网页地址复制到浏览器地址栏中打开：</p>'
		.'<a href="'.site_url('user/reset').'/'.$change_key.'">'.site_url('user/reset').'/'.$change_key.'</a>'
		.'<p>如果您没有重置密码，请忽略此邮件。</p>';
		$content_footer = '</body></html>';
		$content = $content_header.$content_body.$content_footer;
		
		//send mail
		$sae_mail = new SaeMail();
		$sae_mail->setOpt(array('content_type'=>'HTML'));
		$ret = $sae_mail->quickSend($to_mail, $title, $content , $setting_mail, $setting_password);
		$sae_mail->clean();
	}
}
?>